package thread.producer;

import java.util.ArrayList;

/**
 * Created by simod on 2019/12/22
 */
class Factory {
    private ArrayList<String> arrayList = new ArrayList<>();

    public synchronized void add() {
        if (arrayList.size() < 20) {
            arrayList.add("0");
        } else {
            try {
                this.notifyAll();
                this.wait();
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
        }
    }

    public synchronized void get() {
        if (arrayList.size() > 0) {
            arrayList.remove(0);
        } else {
            try {
                this.notifyAll();
                this.wait();
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
        }
    }

}

public class FactoryManager {
    private static Factory factory = new Factory();

    public static Factory getFactory() {
        return factory;
    }
}
